package com.jinglvhuanjing.app.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatTextView;

import java.util.HashMap;

public class CustomTextView extends AppCompatTextView {

    private static final String TAG = "common";

    public CustomTextView(@NonNull Context context) {
        super(context);
    }

    public CustomTextView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomTextView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private String mLabel;
    private String mKey;

    public void setParamTag(String label , String key){
        Log.d(TAG , String.format("设置输入框参数标识：LABEL = %s , KEY = %s " , label , key));
        this.mLabel = label;
        this.mKey = key;
    }

    public HashMap<String , String> getValueMap(){
        HashMap<String , String> valueParam = new HashMap<>();
        if(TextUtils.isEmpty(this.mKey)){
            Log.d(TAG , String.format("获取输入框值：LABEL = %s , KEY = %s , VALUE = %s" , this.mLabel , this.mKey , "NULL"));
            return valueParam;
        }
        String text = getText().toString();
        String value =TextUtils.isEmpty(text) ? "" : text;
        valueParam.put(this.mKey ,  value);
        Log.d(TAG , String.format("获取输入框值：LABEL = %s , KEY = %s , VALUE = %s" , this.mLabel , this.mKey , value));
        return valueParam;
    }
}
